package com.gfxy.modules.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gfxy.modules.common.service.IStaffTreeService;
import com.gfxy.modules.system.entity.SysDepart;
import com.gfxy.modules.system.mapper.SysDepartMapper;
import com.gfxy.modules.system.model.SysDepartTreeModel;
import com.gfxy.modules.system.util.FindsDepartsChildrenUtil;
import org.jeecg.common.constant.CommonConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: lijixin 2021/10/6 7:53 下午
 */
@Service
public class StaffTreeServiceImpl implements IStaffTreeService {

    @Autowired
    private SysDepartMapper sysDepartMapper;

    @Override
    public List<SysDepartTreeModel> queryEducationDepTreeList() {
        LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
        query.and(wp -> wp.eq(SysDepart::getOrgType,"3").or().eq(SysDepart::getOrgType,"0"));
        query.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
        query.orderByAsc(SysDepart::getDepartOrder);
        List<SysDepart> list = sysDepartMapper.selectList(query);
        for (SysDepart sysDepart : list) {
            if(sysDepart.getParentId().equals("3")){
                sysDepart.setParentId("A05");
            }
        }
        List<SysDepartTreeModel> listResult = FindsDepartsChildrenUtil.wrapTreeDataToTreeList(list);
        return listResult;
    }

    @Override
    public List<SysDepartTreeModel> queryEducationDepTreeListByOrgCode(String orgCode) {
        LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();

        query.eq(SysDepart::getOrgCode, orgCode);

        query.and(wp -> wp.eq(SysDepart::getOrgType,"3").or().eq(SysDepart::getOrgType,"0"));
        query.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());

        query.orderByAsc(SysDepart::getDepartOrder);
        List<SysDepart> list = sysDepartMapper.selectList(query);

        List<SysDepartTreeModel> listResult = FindsDepartsChildrenUtil.wrapTreeDataToTreeList(list);
        return listResult;
    }
}
